//
//  KLClient.h
//  WebRTCDemo_iOS
//
//  Created by szblsx2 on 2020/3/5.
//  Copyright © 2020 szblsx2. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "KLAppDefine.h"
@class KLClient;

NS_ASSUME_NONNULL_BEGIN

@protocol KLClientDelegate <NSObject>

@required
/**以下为代理KLClient代理用来回调信令服务器响应事件*/
// 处理发布流响应
- (void)klClient:(KLClient *)client respPublishWithMid:(NSString *)strMid answerSdp:(NSString *)sdp;
// 处理共享流响应
- (void)klClient:(KLClient *)client respScreenWithMid:(NSString *)strMid answerSdp:(NSString *)sdp;
// 处理订阅流响应
- (void)klClient:(KLClient *)client respSubscribeWithMid:(NSString *)strMid subId:(NSString *)subId answerSdp:(NSString *)sdp;
// 处理有流加入消息
- (void)klClient:(KLClient *)client respStreamAddWithStreamId:(NSString *)streamId userId:(NSString *)userId;
// 处理有流移除消息
- (void)klClient:(KLClient *)client respStreamRemoveWithMid:(NSString *)strMid userId:(NSString *)userId;
// 处理获取到房间用户列表消息
- (void)klClient:(KLClient *)client respRoomUserList:(NSArray<KLMeetUser *> *)userList;
// 处理有人加入消息
- (void)klClient:(KLClient *)client respPeerJoinWithNewUser:(KLMeetUser *)newUser;
// 处理有人离开消息
- (void)klClient:(KLClient *)client respPeerLeaveWithUserId:(NSString *)userId;
// 处理会议广播消息
- (void)klClient:(KLClient *)client respMeetingNotificationWithType:(KLNotifiType)type targetUserId:(NSString *)targetUserId state:(BOOL)state;

@end

@interface KLClient : NSObject
//网络状态回调
@property (nonatomic, copy) void(^socketStatusBlock)(NSInteger code);

/**
*  初始化方法
*  @param delegate 代理
*/
- (instancetype)initWithDelegate:(id<KLClientDelegate>)delegate;

/**
*  连接socket
*  @param sevrerUrl 信令服务器地址
*  @param success    连接状态
*/
- (void)startWithServerUrl:(NSString *)sevrerUrl success:(void(^)(BOOL))success;

/**
*  断开连接
*/
- (void)close;

/**
 *  发送创建加入房间信令
 */
- (void)sendJoin:(NSString *)rid uid:(NSString *)uid info:(NSDictionary *)info completion:(void(^)(BOOL result))completion;
/**
*  发送离开房间信令
*/
- (void)sendLeave:(NSString *)rid uid:(NSString *)uid;
/**
*  发送推流信令
*/
- (void)sendPublish:(NSString *)rid sdp:(NSString *)sdp bScreen:(BOOL)bScreen;
/**
*  发送取消推流信令
*/
- (void)sendUnpublish:(NSString *)rid mid:(NSString *)mid;
/**
*  发送订阅流信令
*/
- (void)sendSubscribe:(NSString *)rid mid:(NSString *)mid sdp:(NSString *)sdp;
/**
*  发送取消订阅流信令
*/
- (void)sendUnsubscribe:(NSString *)rid mid:(NSString *)mid;
/**
*  发送IceCandidate信令
*/
- (void)sendIceCandidate:(NSString *)rid mid:(NSString *)mid object:(NSDictionary *)object bPub:(BOOL)bPub;

/**发送会议广播*/
- (void)sendMeetingNotification:(NSString *)rid type:(KLNotifiType)notifiType myUserId:(NSString *)myUserId targetUserId:(NSString *)targetUserId state:(BOOL)state;

@end

NS_ASSUME_NONNULL_END
